const pictureLoader = (
  url: string,
  option = { cors: true },
): Promise<HTMLImageElement> => {
  return new Promise(
    (
      resolve: (el: HTMLImageElement) => void,
      reject: (reason: unknown) => void,
    ) => {
      const picture = new Image();
      if (option.cors) {
        picture.crossOrigin = 'anonymous';
      }
      picture.onload = () => {
        resolve(picture);
      };
      picture.onerror = (error) => {
        reject(error);
      };
      picture.src = url;
    },
  );
};

export { pictureLoader };
